// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   productProvider_draft_ok.java

package draft.purchase;

import include.nseer_cookie.counter;
import include.nseer_cookie.exchange;
import include.nseer_db.nseer_db_backup1;
import java.io.IOException;
import java.sql.ResultSet;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataTag;

public class productProvider_draft_ok extends HttpServlet
{

	public productProvider_draft_ok()
	{
	}

	public synchronized void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		try
		{
			HttpSession session = request.getSession();
			nseer_db_backup1 purchase_db = new nseer_db_backup1(dbApplication);
			if (purchase_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				counter count = new counter(dbApplication);
				ValidataTag vt = new ValidataTag();
				String product_providers_recommend_ID = request.getParameter("product_providers_recommend_ID");
				String provider_IDn[] = request.getParameterValues("provider_ID");
				int m = 0;
				for (int j = 1; j < provider_IDn.length; j++)
				{
					String sql3 = (new StringBuilder("select * from purchase_product_providers_recommend_details where product_providers_recommend_ID='")).append(product_providers_recommend_ID).append("' and provider_ID='").append(provider_IDn[j]).append("'").toString();
					ResultSet rs3 = purchase_db.executeQuery(sql3);
					if (rs3.next())
					{
						String provider_ID_repeat = rs3.getString("provider_ID");
						m++;
					}
				}

				String provider_amount = request.getParameter("provider_amount");
				int num = Integer.parseInt(provider_amount);
				if (m != 0)
					response.sendRedirect((new StringBuilder("draft/purchase/productProvider_ok_a.jsp?product_providers_recommend_ID=")).append(product_providers_recommend_ID).toString());
				else
				if (num == 0 && provider_IDn.length == 1)
				{
					response.sendRedirect((new StringBuilder("draft/purchase/productProvider_ok_b.jsp?product_providers_recommend_ID=")).append(product_providers_recommend_ID).toString());
				} else
				{
					String recommender = request.getParameter("recommender");
					String bodyc = new String(request.getParameter("recommend_describe").getBytes("UTF-8"), "UTF-8");
					String recommend_describe = exchange.toHtml(bodyc);
					String change_time = request.getParameter("change_time");
					String register = request.getParameter("register");
					if (vt.validata((String)dbSession.getAttribute("unit_db_name"), "purchase_product_providers_recommend", "product_providers_recommend_ID", product_providers_recommend_ID, "check_tag").equals("5") || vt.validata((String)dbSession.getAttribute("unit_db_name"), "purchase_product_providers_recommend", "product_providers_recommend_ID", product_providers_recommend_ID, "check_tag").equals("9"))
					{
						try
						{
							for (int i = 1; i <= num; i++)
							{
								String tem_provider_name = (new StringBuilder("provider_name")).append(i).toString();
								String tem_provider_ID = (new StringBuilder("provider_ID")).append(i).toString();
								String provider_name = request.getParameter(tem_provider_name);
								String provider_ID = request.getParameter(tem_provider_ID);
								String sql1 = (new StringBuilder("update purchase_product_providers_recommend_details set details_number='")).append(i).append("' where product_providers_recommend_ID='").append(product_providers_recommend_ID).append("' and provider_ID='").append(provider_ID).append("'").toString();
								purchase_db.executeUpdate(sql1);
							}

							String provider_namen[] = request.getParameterValues("provider_name");
							for (int j = 1; j < provider_IDn.length; j++)
							{
								int details_number = num + j;
								String sql4 = (new StringBuilder("insert into purchase_product_providers_recommend_details(product_providers_recommend_ID,details_number,provider_ID,provider_name) values ('")).append(product_providers_recommend_ID).append("','").append(details_number).append("','").append(provider_IDn[j]).append("','").append(provider_namen[j]).append("')").toString();
								purchase_db.executeUpdate(sql4);
							}

							String sql = (new StringBuilder("update purchase_product_providers_recommend set recommend_describe='")).append(recommend_describe).append("',register='").append(register).append("' where product_providers_recommend_ID='").append(product_providers_recommend_ID).append("'").toString();
							purchase_db.executeUpdate(sql);
						}
						catch (Exception ex)
						{
							ex.printStackTrace();
						}
						response.sendRedirect("draft/purchase/productProvider_ok.jsp?finished_tag=0");
					} else
					{
						response.sendRedirect("draft/purchase/productProvider_ok.jsp?finished_tag=1");
					}
				}
				purchase_db.commit();
				purchase_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
